package com.heima.wemedia.controller.v1;


import com.heima.common.constant.WemediaConstants;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.dto.WmMaterialDto;
import com.heima.wemedia.service.WmMaterialService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("/api/v1/material")
@Api("图片上传到Oss")
public class WmMaterialController {
    @Autowired
    WmMaterialService wmMaterialService;

    @ApiOperation("图片上传到OSS")
    @PostMapping("/upload_picture")
    public ResponseResult upload(MultipartFile multipartFile){
        return wmMaterialService.upload(multipartFile);
    }

    @ApiOperation("自媒体列表展示")
    @PostMapping("/list")
    public ResponseResult list(@RequestBody WmMaterialDto dto){
        return wmMaterialService.imageList(dto);
    }

    @ApiOperation("图片删除")
    @GetMapping("/del_picture/{id}")
    public ResponseResult delPicture(@PathVariable("id") Integer id){
        return wmMaterialService.delPicture(id);
    }

    @ApiOperation("取消收藏")
    @GetMapping("/cancel_collect/{id}")
    public ResponseResult cancelCollect(@PathVariable("id") Integer id){
        return wmMaterialService.collect(id,WemediaConstants.CANCEL_COLLECT_MATERIAL);
    }

    @ApiOperation("收藏")
    @GetMapping("/collect/{id}")
    public ResponseResult collect(@PathVariable("id") Integer id){
        return wmMaterialService.collect(id,WemediaConstants.COLLECT_MATERIAL);
    }
}
